package com.xingchi.tornado.security.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 用户名密码登录
 *
 * @author xiaoya
 * @date 2024/9/27 14:35
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class UsernamePasswordAuthenticationToken extends AbstractAuthenticationToken {

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    public UsernamePasswordAuthenticationToken() {
        super(new ArrayList<>());
    }

    public UsernamePasswordAuthenticationToken(String username, String password, boolean isAuthenticated, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.username = username;
        this.password = password;
        this.setAuthenticated(isAuthenticated);
    }

    @Override
    public Object getCredentials() {
        return password;
    }

    @Override
    public Object getPrincipal() {
        return username;
    }
}
